import { Form } from "antd";
import { productinboundorderForcedComplete, productinboundorderCancelled } from "../service";
import { CommonModal } from "@/views/components/CommonModal";

const ForceCompletionModal = ({ visible, checkedRows, handleCancel, fetchList, filteredArray }) => {
	const [form] = Form.useForm();

	const onOk = async () => {
		if (visible == "Cancellation") {
			// 作废
			const { success } = await productinboundorderCancelled(filteredArray.map(x => x.inboundOrderNo));
			if (success) {
				onCancel();
				fetchList();
			}
		} else {
			// 强制完成
			const { success } = await productinboundorderForcedComplete(filteredArray.map(x => x.inboundOrderNo));
			if (success) {
				onCancel();
				fetchList();
			}
		}
	};
	const onCancel = () => {
		handleCancel();
		form.resetFields();
	};

	return (
		<CommonModal
			title={{ title: visible == "Cancellation" ? "作废" : "强制完成" }}
			className="views-table-dialog"
			visible={true}
			onOk={onOk}
			onCancel={onCancel}
			width="333px"
			minHeight="150px"
		>
			<div>
				<div>
					本次操作数量：<span style={{ color: "rgba(240, 61, 41, 1)" }}>{filteredArray.length}</span>
				</div>
				<div>强制完成后对应的入库单的状态将更改为已完成 请确认是否确认执行该操作</div>
			</div>
		</CommonModal>
	);
};

export default ForceCompletionModal;
